
#include <bur/plctypes.h>
#ifdef __cplusplus
	extern "C"
	{
#endif
	#include "ViSupport.h"
#ifdef __cplusplus
	};
#endif
/* abstraction of signal scheduling */
void SignalScheduler(struct SignalScheduler* inst)
{
	/*TODO: Add your code here*/
	if ((inst->pCycTime == 0) || (inst->pSignal == 0) || (inst->pSignalDuration == 0))
		return;
	
	if (inst->Enable && !inst->oldEnable)
	{
		inst->timer = 0;
		inst->signalCurrent = 0;
	}
	
	if (inst->Update && !inst->oldUpdate)
	{
		inst->timer = 0;
		inst->signalCurrent = 0;
	}
	
	if (inst->Enable)
	{
		inst->timer += *inst->pCycTime;
		struct SignalDuration_typ* pCurrentSignal = &inst->pSignalDuration[inst->signalCurrent];
		*inst->pSignal = pCurrentSignal->Value;
		if (inst->timer >= pCurrentSignal->Time * 1000000)
		{
			inst->signalCurrent++;
			inst->signalCurrent %= inst->SignalNum;
		}
	}
	else
	{
		inst->timer = 0;
		inst->signalCurrent = 0;
	}
	
	inst->oldEnable = inst->Enable;
	inst->oldUpdate = inst->oldUpdate;
}
